package com.jun.common.core.exception;

import com.jun.common.core.entity.page.ResultCode;
import lombok.Data;

/**
 * @author yuejun.li
 * @date 2023/7/10 10:42:07
 * 业务异常类
 */
@Data
public class ServiceException extends RuntimeException{

    private static final long serialVersionUID = 1L;

    /**
     * 错误码
     */
    private int code;

    /**
     * 错误提示
     */
    private String message;

    /**
     * 错误明细，内部调试错误
     * <p>
     * 和 一致的设计
     */
    private String detailMessage;

    /**
     * 空构造方法，避免反序列化缺陷
     */
    public ServiceException() {
    }

    public ServiceException(ResultCode resultCode) {
        this.message = resultCode.getMessage();
        this.code = resultCode.getCode();
    }

    public ServiceException(String message) {
        this.message = message;
    }

    public ServiceException(String message, int code) {
        this.message = message;
        this.code = code;
    }

    public String getDetailMessage() {
        return detailMessage;
    }

    public String getMessage() {
        return message;
    }

    public int getCode() {
        return code;
    }

    public ServiceException setMessage(String message) {
        this.message = message;
        return this;
    }

    public ServiceException setDetailMessage(String detailMessage) {
        this.detailMessage = detailMessage;
        return this;
    }
}
